package com.bobo.service.favourite;

import com.bobo.dao.favourite.FavouriteDaoImpl;
import com.bobo.dao.favourite.IFavouriteDao;
import com.bobo.dto.Counts;
import com.bobo.dto.Page;
import com.bobo.model.Favourite;
import com.bobo.model.Topic;

import java.util.List;

/**
 * Created by bobo on 16-10-28.
 */
public class FavouriteServiceImpl implements IFavouriteService {

    IFavouriteDao favouriteDao = new FavouriteDaoImpl();
    @Override
    public Integer create(Favourite favourite) {
        return favouriteDao.create(favourite);
    }

    @Override
    public boolean delete(Favourite favourite) {
        return favouriteDao.delete(favourite);
    }

    @Override
    public Page<Topic> getTopics(Integer userId, Integer current, Integer pageSize) {
        Page<Topic> page = new Page<>();
        page.setCurrent(current);
        page.setPageSize(pageSize);
        page.setList(favouriteDao.getTopics(userId,current,pageSize));
        Integer count = favouriteDao.getCount(null,userId);
        float pagenum = count.floatValue()/pageSize.floatValue();
        page.setPageNum((int) Math.ceil(pagenum));
        return page;
    }

    @Override
    public Integer getCount(Integer topicId) {
        return favouriteDao.getCount(topicId,null);
    }

    @Override
    public boolean query(Favourite favourite) {
        return favouriteDao.query(favourite);
    }

    @Override
    public Counts getCounts(Integer userId) {
        return favouriteDao.getCounts(userId);
    }
}
